package com.atguigu.gmall.payment.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentContext paymentContext;

    @PostMapping("/pay")
    public ResponseEntity<String> pay(@RequestParam String paymentType, @RequestParam BigDecimal amount) {
        paymentContext.executePay(paymentType, amount);
        return ResponseEntity.ok("Payment successful!");
    }

    @PostMapping("/refund")
    public ResponseEntity<String> refund(@RequestParam String paymentType, @RequestParam BigDecimal amount) {
        paymentContext.executeRefund(paymentType, amount);
        return ResponseEntity.ok("Refund successful!");
    }

    @PostMapping("callback/notify")
    @ResponseBody
    public String callbackNotify(@RequestParam Map<String, String> paramsMap) {
        return paymentContext.executeCallback("alipay", paramsMap);
    }

}